var express = require('express');
var router = express.Router();
var sign = require('./sign.js');
var bodyParser = require('body-parser');
var des = require('./des.js');
/* GET home page. */
router.get('/', function(req, res) {
    var pathUrl = req.originalUrl;
    if(req.session.windows){
        res.render('login');
    }else{
        res.render('h5/login')
    }

});
router.post('/',function(req,res){
    var data=req.body;
    if(req.body.vcode==req.session.code){
        delete data.vcode;
        data.pwd=des.strDec(data.pwd,1,2,3).split(',')[1];
        sign.loginDataReq(req,data,'/sysmanage/account/userLogin',"POST",function(ResData){
            if(ResData!=""){
                req.session.user=data.usercode;
                delete req.session.vcode;
                req.session.apikey=ResData.apikey;
                req.session.role=ResData.data;
                res.send(ResData);
            }
        });
    }else{
        res.send({ message: '验证码错误', statusCode: '300' });
    }
})
module.exports = router;
